import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
Vue.config.productionTip = false

import './assets/vantui'

import './common/flexible'

import api from './request/api'
Vue.prototype.$api = api

router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) {
        const user = Object.keys(store.state.user).length > 0 ? store.state.user : JSON.parse(sessionStorage.getItem('mobile')).user
        if (Object.keys(user).length > 0) {
            next()
        } else {
            next({
                path: '/login',
                query: {
                    redirect: to.fullPath
                }
            })
        }
    } else {
        next()
    }
})

new Vue({
    store,
    router,
    render: h => h(App)
}).$mount('#app')